package hb.watcher.monitor;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class NotificationMan extends Activity{
	
	private CheckBox check_notify_say;
	private CheckBox check_notify_yell;
	private CheckBox check_notify_guild;
	private CheckBox check_notify_whisper;
	private CheckBox check_notify_bg;
	private CheckBox check_notify_party;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
    	super.setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    	
    	setContentView(R.layout.notification);
    	
    	final Config conf = new Config();
    	conf.load();
    	
    	
    	check_notify_say = (CheckBox)findViewById(R.id.notify_say);
    	check_notify_yell = (CheckBox)findViewById(R.id.notify_yell);
    	check_notify_guild = (CheckBox)findViewById(R.id.notify_guild);
    	check_notify_whisper = (CheckBox)findViewById(R.id.notify_whisper);
    	check_notify_bg = (CheckBox)findViewById(R.id.notify_bg);
    	check_notify_party = (CheckBox)findViewById(R.id.notify_party);
    	
    	
    	if(!notEmpty(conf.get("notify_say")))
    		check_notify_say.setChecked(false);
    	else
    	{
    		if(conf.get("notify_say").equals("true"))
    			check_notify_say.setChecked(true);
    		else
    			check_notify_say.setChecked(false);
    	}
    	
    	
    	if(!notEmpty(conf.get("notify_yell")))
    		check_notify_yell.setChecked(false);
    	else
    	{
    		if(conf.get("notify_yell").equals("true"))
    			check_notify_yell.setChecked(true);
    		else
    			check_notify_yell.setChecked(false);
    	}
    	
    	if(!notEmpty(conf.get("notify_guild")))
    		check_notify_guild.setChecked(false);
    	else
    	{
    		if(conf.get("notify_guild").equals("true"))
    			check_notify_guild.setChecked(true);
    		else
    			check_notify_guild.setChecked(false);
    	}
    	
    	if(!notEmpty(conf.get("notify_whisper")))
    		check_notify_whisper.setChecked(true);
    	else
    	{
    		if(conf.get("notify_whisper").equals("true"))
    			check_notify_whisper.setChecked(true);
    		else
    			check_notify_whisper.setChecked(false);
    	}
    	
    	if(!notEmpty(conf.get("notify_bg")))
    		check_notify_bg.setChecked(false);
    	else
    	{
    		if(conf.get("notify_bg").equals("true"))
    			check_notify_bg.setChecked(true);
    		else
    			check_notify_bg.setChecked(false);
    	}
    	
    	if(!notEmpty(conf.get("notify_party")))
    		check_notify_party.setChecked(false);
    	else
    	{
    		if(conf.get("notify_party").equals("true"))
    			check_notify_party.setChecked(true);
    		else
    			check_notify_party.setChecked(false);
    	}
    	
    	
    	Button btn = (Button) findViewById(R.id.notify_button_save);
    	btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	// set notify say
            	if(check_notify_say.isChecked())
            		conf.set("notify_say", "true");
            	else
            		conf.set("notify_say", "false");
            	
            	// set notify yell
            	if(check_notify_yell.isChecked())
            		conf.set("notify_yell", "true");
            	else
            		conf.set("notify_yell", "false");
            	
            	// set notify guil
            	if(check_notify_guild.isChecked())
            		conf.set("notify_guild", "true");
            	else
            		conf.set("notify_guild", "false");
            	
            	// set notify whisper
            	if(check_notify_whisper.isChecked())
            		conf.set("notify_whisper", "true");
            	else
            		conf.set("notify_whisper", "false");
            	
            	// set notify bg
            	if(check_notify_bg.isChecked())
            		conf.set("notify_bg", "true");
            	else
            		conf.set("notify_bg", "false");
            	
            	// set notify party
            	if(check_notify_party.isChecked())
            		conf.set("notify_party", "true");
            	else
            		conf.set("notify_party", "false");
            	
            	
            	conf.store();
                
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            }
    	});
	}
	
	public static boolean notEmpty(String s) {
   	 return (s != null && s.length() > 0);
   	}
	
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        	finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
